import { IChartSeriesPie } from '@ibiz/model-core';
import { ECElementEvent, PieSeriesOption, SeriesOption } from 'echarts';
import { BaseSeriesGenerator, CatalogData } from './base-series-generator';

/**
 * 饼图序列生成器
 * @author lxm
 * @date 2023-06-11 06:19:03
 * @export
 * @class PieSeriesGenerator
 * @extends {BaseSeriesGenerator<IChartSeriesPie>}
 */
export class PieSeriesGenerator extends BaseSeriesGenerator<IChartSeriesPie> {
  protected calcStaticOptions(): SeriesOption {
    const options = super.calcStaticOptions() as PieSeriesOption;

    options.label!.formatter = '{b}: {d}%({c})';
    options.label!.position = 'outside';

    return options;
  }

  protected calcSeriesData(catalogData: CatalogData): {
    name: string;
    value: IData[];
  }[] {
    return Object.keys(catalogData).map(catalog => {
      const data = catalogData[catalog];
      return { name: catalog, value: [data.value, data.deData?.srfkey] };
    });
  }

  getSrfkeyByParams(params: ECElementEvent): string {
    return (params.value as IData)[1];
  }
}
